package com.brilliace.makeXML;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
public class MakeXML {
	public Format FormatXML(){
		Format format =Format.getCompactFormat();
		format.setEncoding("utf-8");
		format.setIndent(" ");
		return format;
	}
	public static void main(String[] args){
		List<String> list =new ArrayList<String>();
		MakeXML m=new MakeXML();
		list.add("id");
		list.add("name");
		list.add("age");
		Element root=new Element("persons");
		Document document =new Document(root);
		for(int i=0;i<list.size();i++){
			Element elements=
					new Element("person");
			elements.addContent(new Element("sid").addContent(new Element("id").setText("1")));
			elements.addContent(new Element("name").setText("2"));
			elements.addContent(new Element("age").setText("3"));
			root.addContent(elements);
		}
		XMLOutputter xmlout=new XMLOutputter(m.FormatXML());
		try {
			xmlout.output(document, new FileOutputStream("src/student.xml"));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
